#include <buola/cv/features/cmatchview.h>
#include <buola/cv/features/cmatch.h>

namespace buola { namespace cvi {
    
CMatchView::CMatchView()
{
    mFeatureView1=new CFeatureView;
    mFeatureView2=new CFeatureView;
    Add(mFeatureView1);
    Add(mFeatureView2);
}

CMatchView::~CMatchView()
{
    
}

void CMatchView::OnExpose(const gui::CExposeEvent &pE)
{
    CMosaicContainer::OnExpose(pE);
}

void CMatchView::OnKeyDown(const gui::CKeyEvent &pE)
{
    if(pE.mKey==KEY_RIGHT)
    {
        SelectMatch(mIndex+1);
    }
    else if(pE.mKey==KEY_LEFT)
    {
        SelectMatch(mIndex-1);
    }

}

void CMatchView::SetFeatures(CFeatureSet &&pSet1,CFeatureSet &&pSet2)
{
    mFeatureView1->SetFeatures(std::move(pSet1));
    mFeatureView2->SetFeatures(std::move(pSet2));
}
    
void CMatchView::SetImages(const img::CPicture &pImage1,const img::CPicture &pImage2)
{
    mFeatureView1->SetImage(pImage1);
    mFeatureView2->SetImage(pImage2);
}

void CMatchView::SetMatches(const std::vector<CMatch> &pMatches)
{
    mMatches=pMatches;
    
    SelectMatch(0);
}

void CMatchView::SelectMatch(int i)
{
    mIndex=i;
    if(mIndex>=0&&mIndex<mMatches.size())
    {
        mFeatureView1->SelectFeature(mMatches[i].mIndex1);
        mFeatureView2->SelectFeature(mMatches[i].mIndex2);
        msg_info() << "dist:" << mMatches[i].mDistance << "\n";
    }
}
    
/*namespace cvi*/ } /*namespace buola*/ }